merged split with sam's code