code cleanup, remove garbage and do refactoring