Add closing code and made regex Python 2.6 compatible