Moved function to proper file; some more work, all done at 20140619