Fixed several errors, added imports etc.