refactor and optimization of certain classes