Further refactoring of code