Cleaned up and simplified, now it's working