Fixed missing match case, cleaned up some code