moving some code around. Fixes to make it build in Fedora 17.