Modified for better preformance. Created more configuration options.