I was trying to keep this PR as small as possible. I saw and dislike all this code too.
Anyway, I've [fixed this](https://github.com/Mirantis/fuelweb/commit/44ab9a7e59728215dc74facfea626848cbcf4126).