Code clean up and better structuring