Updated and refacored code for better readability and removed unused types