added TODO and tweaked error handling