Refactoring to use OTP