refactoring stuff to try to optimize, still have a low frame rate though :(