minor bugs and added unistd for close() func