wrote custom case function