Removed some spaghetti code