Refactoring & simplifying code