this should perhaps be unit tested