See the comments in code to get idea how to realize this