Fixed complex SDP, and cleaned up a lot of code in the process.