gradient added
minor changaes
reducing memory consumption
minor changes