added the whole code