This also includes a minor refactor of everything, as well as some optimizations. The bitmap operations have been moved into a separate file because they are probably gonna come in handy in other parts of the system as well.