Does not fixes all, but adds some error checking
Not working now, after it did yesterday in a slower machine. Comitting and pushing for asking in StackOverflow