Added almost all of the functionality, nothing is tested yet