added details and cleaned up logic