updated code to call type() and added an error check in isValidMove in
model