Implemeted changes/bug fixes from Github discussion