switched to class model, cleaned up some code