done using cases, must find more elegance