Fix some type bugs, add few more functions