fixes issues #335 and #533