refactored some parts