fixed call logic (hopefully). also some refactoring