Refactor several classes to be more elegant