Updated and organized code