Refactored some old codes