Cleaned and added feasibility check