working version, needs some bugfixing and pretty print