New Functions

Corrected some logic and added some new features