fixed out of ports bug by adding port semaphores