updated code with more advanced features