Improved functionality and fixed some bugs