Bug fix and refactoring towards OR function