Showing Show all link when necessary and cleaning up code