Made function concise
Improved test