Bastardized stopping conditions, should be good enough for most purposes