Fixed bit shifting.
Ready to integrate with main branch.