updated comments, cleaned up the API, made helper routines.