updated for easier searching, included much more error checking