re-organized some class logic, broke up file into three parts