made it less error prone

codesniffed
various minor stuff...