Updated code based on feedback from @mateusz