Working code with everything in place

This code will be the base from now on