Fixed the freezing bug