more  efficient code + added messages