Fixed code for building bitmap.
Added basic unit tests.