Serial code (submitted for Astro 585)