Fixed some TODO bugs and features.
Added error handling.