Not using desired algorithm but it was as close as I could get for now.