Extracted relevant parts of Paloma source code.