Refactor code, remove unused fucntions