better error checking and documentation