working, count char is a bit ugly, could use refactoring if possible