This code might still have some bugs