angular bug fixing, refactoring