Simplified bit operations, cleaned up and added some switch-cases

I hope I haven't broken anything. Let me know if you don't like anything.
Same here