move code around for readability