Refactored a bunch of code. Also, better indentation