got it to work for all cases. to do: make it pretty