Reorganize code to more rails way