refactored to clean up spacing, comments and added better pagination