added tests, refactored request handler