bugfixes and added sendError method
bugfixes