refactored code and added alignment