refactored using loops, added css styling