avoid seg fault
minor improvements