Rewrite using OOP best practices