block and errors

Added application block factory and fixed nasty bug with error handling