Updated to work nicely with loop shortcode