added simple locking routine and started to implement the port stuff