Cleaned up implementation from Music Hack Day