avoiding undefined behavior