optimalised the check connection function
added check cache function
removed some unnecery code