refactored some neater code