Help with simple rig/model

Hi, I’ve been trying to get my low poly robot model rigged but I’m having a bit of trouble as the bones are acting strange.
Maybe if someone could tweak the model or the rig to get it working that would be great :D.

I’ve done some weight painting but it doesn’t seem to solve the problem.
It will be used in the game engine.

Rigging help.blend (568 KB)

Any help or working files would be greatly appreciated


EDIT: turns out that the rig didn’t take too kindly to the merged vertices. I ended up remodelling and leaving the extra vertices around the bent joint.