improved logic works