fixed formatting bug and cleaned up code