updated code with additional tests