improved api and exception handling