refactoring to be more go style code, doesnt work yet