Removed some superflous error if-tests and taking of dm from commandline.
Added variable dm with help from Paulmag