better output and legality implemented