implemented the stubs and added comments
minor changes to make the code more understandable