Rearranged functions and added remove whitespace