Refactored, optimised, cleaned code