added comments and made basic function work correctly