Correcting bugs and changing according to latest implementation