added packStart and packEnd
added comments + some refactoring