added close icon, refactored some code