Fixing bugs on wrong angular JS implementation