refactored by velja and nikola