Code Clean up

Clean up the code so there won't be so many unnecessary if and else.