reformatted, included NullObject for errors, replaces long conditionals with hash options where possible.