refactor and added back functionality