It would be much easier to read this code if it was indented in a consistent fashion.