e2e testing and some refactoring