added comments and fixed some issues