Some code refactoring

I refactored the code a bit to more Ruby. Let me know what you think of these changes.