add constraints & refactor