improved commenting and cleaned up code