Major refactorign