final debugging and added comments