Initial code (using theta functions)