Fixed issues, improved implementation, added functionality