Added comments with credit to Pavel Kirjanas