refactoring some code to make readable and understandable for new ruby users