added layout algorithm