Cleaned up

Moved declarations to top to make it pretty for peter.