updated with empty checking