Initial set implementation (untested!)
Minor changes to make compilable