Extended test case, small bug fix, and shortened some code