Add a licence, clean up and debug the code.