Simplified the code a bit, had perfect results each time.