refactored most of the code
refactored most of the code