First semi-working version. Not all supported parameters written to output yet.