IMported new code

Changed and improved the code