moving code around for readability