moving code around for clarity