Cleaned up code, fixed constraint issue