Fixed Critical code issues