Added more functions, made exception handling more consistent.