Completely rewritten the code from ground up

I have completely rewritten the code from ground up, now allows greater user freedom to define operation parameters.