Improved solution for 1189.