created code for spawn and end point