This is based on initial version from Arash (https://github.com/aaghevli).