cleanup code, comment, add types