added this to make it a module
made various small changes, added new options