Some bug and style fixes
Refactored, esp WriteStmt
Passed Beck's test, now to work on our own