Fixed placement of code and made it organized.