Added error checking, added destroying of buffer mutexes, fixed bug where prime numbers were potentially missed.