cleaned up code quite a bit
implemented case