implemented sourcemap generation and cleaned up code
added tests