Refactor, remove unused code