Made repairs, wrote better tests