Fix code issues and add conditions about required fields