Improve speed and error handling