Add bit array
Add some error checking
Fix one off by one error
Fix other off by one error