Further implementation and cleanup