refactored the code and started to add some selenium tests