added header comments and cleaned up code