remove unused code and reorganize