Reordered code to fit gem structure