fixed errors and error handling (most parts)