Fix soma bugs and refactoring.