handle npe
cleaned up import
fixes #187
formatting
api cleanup