restructured and cleaned up code