Re-org code a bit