Fixed several bugs, styled up resulting code (extra spaces)