Removed function declarations, and reordered functions as needed.