Removed some unnecessary code and comments
Added zdir argument. Fixed line lengths and trailing whitespace.