refactoring code to be responsive