cleaned up code, comments, added min structure