Reduce some redundant code, bugfix, refs #26