cleaned up code and removed duplicates