Added tests and fixed some port implementation