added a version with shalins good code.