Refactor finally compiling and functional