Fixed whitespaces and reorganized code