output improved, some checks introduced