Refactor and remove useless ruby code