code refactor, further simplification to julia like syntax, still not working