Working prototype (except one edge case)