adding checks in to prevent exception