Organized and cleaned up code