code merged with tos branch