Changed code

Made code more organized and clearer