Bugs fixed.
To do: optimize memory layout.