Fixing errors pointed out by dialyzer

Fixing type and pattern matching errors noted by dialyzer