refactored ruby code and separated to new files