more logic and debug