added support for cpu / memory limits and fixed a few bugs

Change-Id: Ibd0726ec86740d8d0c5f3859bb09bcc5f7098587