UPDATE: Moved hardtyped code to if __name__ == __main__ to faciliate importing.