Removed bugs but doesn't work as intended