fixed some cmd invocation issues, code cleanup