Added OpenMP support. Minor refactoring.