Some more editing to do here to get to final version - running currently on Amazon virtual instance - given long calculation time