Refactor to easier handling and more ruby-like syntax