added comments and tested on my stuff.