refactored to allow for more function calls