Cleaned initilal code up, added some logic